package com.pktechan.api.tradeOrderStatus;

import com.alibaba.fastjson.JSONObject;
import com.pktechan.api.enumeration.ChangeTradeOrderStatusEnum;
import com.pktechan.api.utils.SpringContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: cloudfloating
 * @description: 改变订单状态策略接口
 * @author: qx.zhang
 * @create: 2021-03-15 11:27
 **/
public class ChangeTradeOrderStateBeanInitialization {

    private static final Logger logger = LoggerFactory.getLogger(ChangeTradeOrderStateBeanInitialization.class);


    /**
     * 首先获取
     *
     * @return
     */
    public static Map<ChangeTradeOrderStatusEnum, ChangeTradeOrderState> getMap() {
        logger.info("init...");

        Map<ChangeTradeOrderStatusEnum, ChangeTradeOrderState> map = new HashMap<ChangeTradeOrderStatusEnum, ChangeTradeOrderState>(ChangeTradeOrderStatusEnum.values().length);

        // 首先获取 ChangeContractState 接口的所有的实现类
        Map<String, ChangeTradeOrderState> clazzMap = SpringContextUtil.getApplicationContext().getBeansOfType(ChangeTradeOrderState.class);

        for (Map.Entry<String, ChangeTradeOrderState> entry : clazzMap.entrySet()) {
            logger.info("解析到的class文件：{}" + entry.getValue().getClass());
            ChangeTradeOrderState changeTradeOrderState = SpringContextUtil.getApplicationContext().getBean(entry.getValue().getClass());
            map.put(changeTradeOrderState.getMappingEnum(), changeTradeOrderState);
        }
        logger.info("解析后的customPropertiesMap:{}" + JSONObject.toJSONString(map));
        return map;
    }
}
